package Executor;


import interfaces.PrimeFinder;

import java.util.concurrent.Callable;

public class Counter implements Callable<Integer>, Runnable {

    private int start;
    private int end;
    private PrimeFinder primeFinder;

    public Counter(int start, int end, PrimeFinder primeFinder) {
        super();
        this.start = start;
        this.end = end;
        this.primeFinder = primeFinder;

    }


    @Override
    public Integer call() throws Exception {
        int result = 0;
        for (int candidate = start; candidate <= end; candidate++) {
            if (primeFinder.isPrime(candidate)) {
                result++;
            }
        }
        return result;
    }


    @Override
    public void run() {
        int result = 0;
        for (int candidate = start; candidate <= end; candidate++) {
            if (primeFinder.isPrime(candidate)) {
                result++;
            }
        }
    }
}